/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved.							  */
/* Open Source Software - may be modified and shared by FRC teams. The code   */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib.  */
/*----------------------------------------------------------------------------*/
#ifndef JOYSTICK_H_
#define JOYSTICK_H_

#include "GenericHID.h"

class DriverStation;

/**
 * Handle input from standard Joysticks connected to the Driver Station.
 * This class handles standard input that comes from the Driver Station. Each time a value is requested
 * the most recent value is returned. There is a single class instance for each joystick and the mapping
 * of ports to hardware buttons depends on the code in the driver station.
 */
class Joystick : public GenericHID
{
public:
	static const unsigned kDefaultXAxis = 1;
	static const unsigned kDefaultYAxis = 2;
	static const unsigned kDefaultZAxis = 3;
	static const unsigned kDefaultTwistAxis = 4;
	static const unsigned kDefaultThrottleAxis = 3;
	typedef enum
	{
		kXAxis, kYAxis, kZAxis, kTwistAxis, kThrottleAxis, kNumAxisTypes
	} AxisType;
	static const unsigned kDefaultTriggerButton = 1;
	static const unsigned kDefaultTopButton = 1;
	typedef enum
	{
		kTriggerButton, kTopButton, kNumButtonTypes
	} ButtonType;

	Joystick(unsigned port);
	virtual ~Joystick();

	unsigned GetAxisChannel(AxisType axis);
	void SetAxisChannel(AxisType axis, unsigned channel);

	virtual float GetX(JoystickHand hand = kRightHand);
	virtual float GetY(JoystickHand hand = kRightHand);
	virtual float GetZ(void);
	virtual float GetTwist(void);
	virtual float GetThrottle(void);
	virtual float GetAxis(AxisType axis);
	float GetRawAxis(unsigned axis);

	virtual bool GetTrigger(JoystickHand hand = kRightHand);
	virtual bool GetTop(JoystickHand hand = kRightHand);
	virtual bool GetBumper(JoystickHand hand = kRightHand);
	virtual bool GetButton(ButtonType button);
	bool GetRawButton(unsigned button);

protected:
	Joystick(unsigned port, unsigned numAxisTypes, unsigned numButtonTypes);

private:
	void InitJoystick(unsigned numAxisTypes, unsigned numButtonTypes);

	DriverStation *m_ds;
	unsigned m_port;
	unsigned *m_axes;
	unsigned *m_buttons;
};

#endif
 
